package leetcode.每日一题;

import org.junit.Test;

import java.util.*;

/**
 * @author ：zsy
 * @date ：Created 2022/3/6 14:23
 * @description：https://leetcode-cn.com/problems/find-good-days-to-rob-the-bank/
 */
public class 适合打劫银行的日子 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.goodDaysToRobBank(new int[]{5, 3, 3, 3, 5, 6, 2}, 2));
    }

    class Solution {
        public List<Integer> goodDaysToRobBank(int[] security, int time) {
            int len = security.length;
            int[] left = new int[len];
            int[] right = new int[len];
            for (int i = 1; i < len; i++) {
                if (security[i] <= security[i - 1]) {
                    left[i] = left[i - 1] + 1;
                }
                if (security[len - 1 - i] <= security[len - i]) {
                    right[len - 1 - i] = right[len - i] + 1;
                }
            }
            List<Integer> ans = new ArrayList<>();
            for (int i = time; i < len - time; i++) {
                if (left[i] >= time && right[i] >= time) {
                    ans.add(i);
                }
            }
            return ans;
        }
    }
}
